package com.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.crm.common.domain.vo.IndexStatisticsVo;
import com.crm.domain.Clue;
import com.crm.domain.dto.PageAndTimeClueDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

import static net.sf.jsqlparser.parser.feature.Feature.update;

@Mapper
public interface ClueMapper extends BaseMapper<Clue> {

    // 分页查询
    List<Clue> pageWithCreatTime(PageAndTimeClueDto pageAndTimeClueDto);

    @Update("update clue set false_count = false_count + 1 where id = #{id}")
    // 根据id更新
    void falseCountAdd(Long id);

    // 将数据更新为公海池
    @Update("update clue set status = '3' where id = #{id}")
    void pushInPool(Long id);


    // 根据活动id查询
    Map<String, Object> countByActivity(Clue clue);

    public List<Clue> selectClueForReport(Clue clue);

    public int countAllClues(@Param("beginCreateTime") String beginCreateTime,
                             @Param("endCreateTime") String endCreateTime);


    List<Map<String, Object>> countAllClueByUser(@Param("indexVo")IndexStatisticsVo vo);

    Integer effectiveCluesNums(@Param("beginCreateTime") String beginCreateTime,
                               @Param("endCreateTime") String endCreateTime);

    @Select("select count(*) from clue where owner = #{userName}")
    Integer countCluesByUser(String userName);

    @Update("update clue set owner = #{transferUserName} where owner = #{userName}")
    void transfer(@Param("userName") String userName, @Param("transferUserName") String transferUserName);
}
